﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="productlist.aspx.cs" Inherits="ncp.Web.page.productlist" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Src="/uc/search.ascx" TagName="search"  TagPrefix="uc" %>
<%@ Register Src="/uc/headTop.ascx" TagName="headTop"  TagPrefix="uc" %>
<%@ Register Src="/uc/headLogo.ascx" TagName="headlogo"  TagPrefix="uc" %>
<%@ Register Src="/uc/menu.ascx" TagName="menu"  TagPrefix="uc" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>中国农业信息化服务商</title>
    <link href="/css/module.css" rel="stylesheet" type="text/css" />
    <link href="/css/page.css" rel="stylesheet" type="text/css" />
    <link href="/css/reset.css" rel="stylesheet" type="text/css" />
    <script src="/js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="/js/common.js" type="text/javascript"></script>
    <script src="/js/paging.js" type="text/javascript"></script>

    <script src="/Plugin/asyncbox/asyncbox.v1.5.beta.min.js" type="text/javascript"></script>
    <style type="text/css">
    .previewbox {
    border: 1px solid #EEEEEE;
    display: none;
    position: absolute;
    width: 200px;
    background-color:#fff;
}
.previewbox .imgdelete {
    background-image: url("/image/close.png");
    background-repeat: no-repeat;
    color: red;
    cursor: pointer;
    height: 16px;
    position: absolute;
    right: 0;
    top: 0;
    width: 16px;
    z-index: 100;
}
</style>
    <script type="text/javascript">
        $(function() {

        getArea("povince", 0, "");
            $("#povince").change(function() {
                var city = $(this).val();
                getArea("city", 1, city);
                getArea("area", 2, $("#city").val());
            });
            $("#city").change(function() {
                getArea("area", 2, $("#city").val());
            });
            $("#povince,#city,#area,#timeLimit").change(function() {
                paging.pageIndex = 1;
                initPaging();
            });
            var key = '<%=Request.QueryString["key"] %>';
            key = key == "" ? "" : key.substring(1);
            $("#txtSearch").val(key);
            $("#searchtype").val(0);
        });
    var paging;
    $(function() {
        paging = new Paging();
        initPaging();
        getRecProduct();
    });

    function initPaging() {
        paging.dataCount = getDataCount();
        paging.loadPagingText();
        paging.query();
    }
    
    function getDataCount() {
        var response = ncp.Web.page.productlist.GetProductCount($.objectToJson(getDic()));
        if (response.value != null) {
            var jsonOBJ = eval(response.value)[0];
            if (jsonOBJ.isreload) {
                return jsonOBJ.msg;
            }
            return 0;
        }
        return 0;
    }

    function getDic() {
        var ele = new Object();
        var province = $("#povince").val();
        var city = $("#city").val();
        var area = $("#area").val();
        if (province != "") {
            ele.provinceID = province;
        }
        if (city != "") {
            ele.cityID = city;
        }
        if (area != "") {
            ele.areaID = area;
        }
        ele.key = '<%=Request.QueryString["key"] %>';
        if (ele.key != "") {
            $("#txtSearch").val(ele.key.substring(1));
            ncp.Web.page.productlist.InsertKey(ele.key);
        }
        var cate = '<%=Request.QueryString["cate"] %>';
        var channel = '<%=Request.QueryString["channel"] %>';
        var pclass = '<%=Request.QueryString["class"] %>';
        var type = '<%=Request.QueryString["type"] %>';
        if (type != "" && pclass != "" && type != "" && cate!="") {
            if (type == "0") {
                if (pclass == "0") {
                    if (channel == "0") {
                        ele.cate = cate;
                    }
                    else {
                        ele.channel = channel;
                    }
                } else {
                    ele.pclass = pclass;
                }
            } else {
                ele.type = type;
            }
        }
        
        if ($("#timeLimit").val() != "") {
            ele.timeLimit = $("#timeLimit").val();
        }
        return ele;
    }
    Paging.prototype.query = function() {
        var rep = ncp.Web.page.productlist.GetProductList(paging.pageIndex - 1, paging.pageSize, $.objectToJson(getDic()));
        if (rep.value != null) {
            var json = eval(rep.value)[0];
            if (json.isreload) {
                $(".bh-zzg-ny-cleftbrt").html(json.msg);
            }
            else {
                alert(json.msg);
            }
        }
    }


    function getRecProduct() {
        var response = ncp.Web.page.productlist.GetRecProduct($.objectToJson(getDic()));
        if (response.value != null) {
            var jsonOBJ = eval(response.value)[0];
            if (jsonOBJ.isreload) {
                $(".bh-zzg-ny-crightnr1").html(jsonOBJ.msg);
            }
            else {
                alert(jsonOBJ.msg);
            }
        }
    }
    //获取地区
    function getArea(dom, type, pId) {
        var response = ncp.Web.page.productlist.GetArea(type, pId);
        if (response.value != "") {
            var jsonOBJ = eval(response.value)[0];
            if (jsonOBJ.isreload) {
                $("#" + dom).html(jsonOBJ.msg);
            } else {
                alert(jsonOBJ.msg);
            }
        }
    }
    function onLeaveMessage(userId) {
        asyncbox.open({
            title: '请填写留言信息',
            id: 'message',
            width: "480px",
            height: "320px",
            modal: true,
            url: '/page/messagebox.aspx',
            ctrlbar: {
                close: false
            },
            buttons: asyncbox.btn.OKCANCEL,
            callback: function(buttonResult, contentWindow, returnValue) {
                if (buttonResult == 'ok') {
                    var username = contentWindow.document.getElementById('username').value;
                    var msgContent = contentWindow.document.getElementById('msgContent').value;
                    var userPhone = contentWindow.document.getElementById('userPhone').value;
                    var userEmail = contentWindow.document.getElementById('userEmail').value;
                    var tbcode = contentWindow.document.getElementById('tbcode').value;
                    if (!contentWindow.checkData()) {
                        return false;
                    }
                    if (!verfiedCode(tbcode)) {
                        return false;
                    }
                    ele.Message_Name = username;
                    ele.Message_Tel = userPhone;
                    ele.Message_Email = userEmail;
                    ele.Message_Note = msgContent;
                    if (isLogin()) {
                        onSendMsg(userId);
                    } else {
                        showLoginBox(userId);
                        return false;
                    }
                }
                return true;
            }
        });
    }
    //判断验证码是否正确
    function verfiedCode(code) {
        var response = ncp.Web.page.productlist.VerificationCode(code);
        if (response.value != null) {
            var jsonOBJ = eval(response.value)[0];
            if (!jsonOBJ.isreload) {
                alert("验证码错误");
                asyncbox.opener('message').onfresh();
                return false;
            } else {
                return true;
            }
        }
        return false;
    }
    
    //判断用户是否已经登录
    function isLogin() {
        var response = ncp.Web.page.productlist.IsLogin();
        return response.value;
    }
    var ele = new Object();
    function showLoginBox(userId) {
        var boo = false;
        asyncbox.open({
            title: '请登录后留言',
            id: 'login',
            width: "330px",
            height: "160px",
            modal: true,
            url: '/Shop/loginbox.aspx',
            ctrlbar: {
                close: false
            },
            buttons: asyncbox.btn.OKCANCEL,
            callback: function(buttonResult, contentWindow, returnValue) {
                if (buttonResult == 'ok') {
                    var username = asyncbox.framer('login_content').document.getElementById('username').value;
                    var pwd = asyncbox.framer('login_content').document.getElementById('password').value;
                    boo = login(username, pwd, userId);
                    if (boo) {
                        asyncbox.close('message');
                    }
                    return boo;
                }
                return true;
            }
        });
        return boo;
    }
    function login(username, pwd,userId) {
        if ($.trim(username) == "") {
            alert("用户名不能为空！");
            return false;
        }
        if ($.trim(pwd) == "") {
            alert("密码不能为空！");
            return false;
        }
        var response = ncp.Web.page.productlist.UserLogin(username, pwd);
        if (response.value != "") {
            var jsonOBJ = eval(response.value)[0];
            if (jsonOBJ.isreload) {
                onSendMsg(userId);
                userStatues();
                return true;
            } else {
                alert(jsonOBJ.msg);
                return false;
            }
        }
        return false;
    }
    function onSendMsg(userId) {
        var response = ncp.Web.page.productlist.OnSaveMessage($.objectToJson(ele), userId);
        if (response.value != "") {
            var jsonOBJ = eval(response.value)[0];
            if (jsonOBJ.isreload) {
                alert(jsonOBJ.msg);
                return true;
            } else {
                if (jsonOBJ.msg == "0") {
                    alert("没有找到该用户！");
                } else {
                alert(jsonOBJ.msg);
            }
                return false;
            }
        }
        return false;
    }
    function onfresh() {
        var rand = Math.random() * 1000;
        $("#checkImage").attr("src", "/work/VerificationCode.aspx?" + rand);
    }
    $(function() {
        $(".cliContact").click(function(e) {
            $("#contactPre").html(getContent($(this).attr("userId")));
            $(".previewbox").css({ "top": e.pageY + 10, "left": e.pageX - 200 });
            $(".previewbox").fadeIn();
        });
    });
    function hidePreview() {
        $('.previewbox').fadeOut();
    }
    function getContent(userId) {
        var rep = ncp.Web.page.productlist.GetContact(userId);
        if (rep.value != null) {
            var jsonOBJ = eval(rep.value)[0];
            if (jsonOBJ.isreload) {
                return jsonOBJ.msg;
            } else {
                return "";
            }
        }
        return "";
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
         <!--Head Begin--> 
<!--Head Top-->
<uc:headTop id="headtop" runat="server" />
<!--Head Logo-->
<uc:headlogo id="headlogo" runat="server" />
<!--Head Nav-->
<div id="head-nav">
	<div id="head-nav-center">
	    <uc:menu ID="menu" runat="server"/>
        <uc:search id="search" runat="server" />
    </div>
</div>
<!--Head End-->
<div class="bh-space"></div>
<div class="wp">
  <div class="bh-zzg-ny-center">
    <div class="bh-zzg-ny-cleft bh-fl">
      <div class="bh-zzg-ny-cleftbt">
        <div class="bh-zzg-ny-cleftbtck bh-fl" style="display: none;">
          <p>查看</p>
          <p class="bh-zzg-ny-cleftbtcklb"><a href="javascript:void()" onclick="setViewStyle(0)">列表</a></p>
          <p class="bh-zzg-ny-cleftbtckdt"><a href="javascript:void()" onclick="setViewStyle(1)">大图</a></p>
          <div class="bh-clear"></div>
        </div>
        <div class="bh-zzg-ny-cleftbtxllb bh-fr" style="float: left;margin-left: 10px;">
        <select id="povince" class="indexSelect">
            <option value="">--所在省份--</option>
        </select>
        <select id="city" class="indexSelect">
            <option value="">--所在地区--</option>
        </select>
        <select id="area" class="indexSelect">
            <option value="">--所在城市--</option>
        </select>
          <select id="timeLimit" class="indexSelect">
            <option value="">所有更新时间</option>
            <option value="7">最近一周</option>
            <option value="30">最近一个月</option>
        </select>
        </div>
        <div class="bh-clear"></div>
      </div>
      <div class="bh-zzg-ny-cleftbr">
        <div class="bh-zzg-ny-cleftbrt">
        </div>
        <div id="paging" class="bh-zzg-ny-cleftbrbottom">

    </div>
      </div>
    </div>
    <div class="bh-zzg-ny-cright bh-fr">
      <div class="bh-zzg-ny-crightbt">
        <h2>极力推荐</h2>
      </div>
      <div class="bh-zzg-ny-crightnr">
        <div class="bh-zzg-ny-crightnr1">
          
          <div class="bh-clear"></div>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="previewbox">
	    <span title="关闭" onclick="hidePreview()" class="imgdelete"></span>
	    <div id="contactPre"></div>
	</div>
<div class="bh-space"></div>
<!--#include file="/uc/footer.htm"-->
    </form>
</body>
</html>
